package com.common.controller;

import com.common.annotation.LogAnnotation;
import com.common.controller.base.BaseAjaxController;
import com.common.dto.RoleDTO;
import com.common.service.RoleService;
import com.common.util.ConstantDefine;
import com.common.util.LogType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/role")
public class RoleController extends BaseAjaxController<RoleDTO> {

    @Autowired
    private RoleService roleService;


    @Override
    public String init(Model model) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String init(RoleDTO entity, Model model) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Object queryByEntity(RoleDTO entity) {
        return null;
    }

    @Override
    public ResponseEntity<Map<String, Object>> save(@Valid RoleDTO entity, BindingResult bindingResult) {
        return null;
    }

    @Override
    public ResponseEntity<Map<String, Object>> update(@Valid RoleDTO entity, BindingResult bindingResult) {
        return null;
    }

    @Override
    public ResponseEntity<Map<String, Object>> delete(@RequestBody List<String> id) {
        return null;
    }

    /**
     * Created by wrl on 2017/07/10
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/updateInit/{id}")
    public RoleDTO updatePageInit(@PathVariable("id") String id) {
        RoleDTO roleDTO = roleService.updateInit(id);
        return roleDTO;
    }

    @Override
    public RoleDTO updateInit(String id) {
        return null;
    }

    /**
     * Created by wrl on 2017/07/10
     *
     * @param entity
     * @return
     */
    @ResponseBody
    @RequestMapping(value = ConstantDefine.UPDATE_REQ)
    @LogAnnotation(description = "修改角色", bizID = LogType.ROLE)
    public Map<String, Object> updateById(RoleDTO entity) {
        Map<String, Object> map = roleService.updateRole(entity);
        return map;
    }

    /**
     * Created by wrl on 2017/07/10
     * 软删除
     *
     * @param entity
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/deleteByIds", method = RequestMethod.GET)
    public Map<String, Object> deleteByIds(RoleDTO entity) {
        List<String> ids = entity.getIds();
        Map<String, Object> map = roleService.deleteRoles(ids);
        return map;
    }

    /**
     * Created by wrl on 2017/07/10
     * 软删除:state=0
     *
     * @param entity
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "deleteById", method = RequestMethod.POST)
    public Map<String, Object> deleteById(RoleDTO entity) {
        Map<String, Object> map = roleService.deleteRole(entity);
        return map;
    }

    @ResponseBody
    @RequestMapping("/selectPaging")
    @LogAnnotation(description = "角色管理页面", bizID = LogType.ROLE)
    public Map<String, Object> selectByPaging(RoleDTO entity) {
        Map<String, Object> resultMap = roleService.selectPaging(entity);
        return resultMap;
    }

    /**
     * Created by wrl on 2017/07/10
     *
     * @param entity
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/save")
    @LogAnnotation(description = "添加角色", bizID = LogType.ROLE)
    public Map<String, Object> saveRole(RoleDTO entity) {
        Map<String, Object> map = roleService.saveRole(entity);
        return map;
    }

    /**
     * Created by wrl on 2017/09/12
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/list")
    public Object getRoleList() {
        List<RoleDTO> list = roleService.selectAll();
        return list;
    }

}
